package com.atguigu.guli.service.edu.controller;


import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.edu.entity.Chapter;
import com.atguigu.guli.service.edu.entity.ChapterVo;
import com.atguigu.guli.service.edu.service.ChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2022-01-04
 */
@RestController
@CrossOrigin
@RequestMapping("/edu/chapter")
public class ChapterController {

    @Autowired
    private ChapterService chapterService;

    @GetMapping("getChapterVideo/{courseId}")
    public R getChapterVideo(@PathVariable("courseId") String courseId){
       List<ChapterVo> list= chapterService.getChapterVideoByCourseId(courseId);
        return R.ok().data("list",list);
    }

    @PostMapping("addChapter")
    public  R addChapter(@RequestBody Chapter chapter){
        chapterService.save(chapter);
        return R.ok();
    }

    @GetMapping("getChapter/{chapterId}")
    public R getChapterInfoById(@PathVariable String chapterId){
        Chapter byId = chapterService.getById(chapterId);
        return R.ok().data("chapter",byId);
    }

    @PostMapping("updateChapter")
    public R updateChapter(@RequestBody Chapter chapter){
        chapterService.updateById(chapter);
        return R.ok();
    }

    @DeleteMapping("deleteChapter/{chapterId}")
    public R deleteChapter(@PathVariable String chapterId){
        chapterService.deleteChapter(chapterId);
        return R.ok();
    }


}

